﻿using BaoVeBienCuong.SelectMap;
using BapVeBienCuong.menu;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace BaoVeBienCuong.Playgame.Button
{
    class ThongBao
    {
        private string name;
        private Texture2D background;
        private Texture2D button;
        private Texture2D guidiem;
        private int linhdiet;
        private int moneyThua;
        private int trangthai;
        private int wave;
        private int dokho;
        private int life;
        private bool isVisible;
        private bool isTouchBando;
        private bool isRepeat;
        private bool isGuiDiem;
        private int TongDiem;
        public ThongBao()
        {
            isVisible = false;
            name = "Thắng cuộc";
            linhdiet = 0;
            moneyThua = 0;
            wave = 0;
            dokho = 0;
        }
        public void set(int trangthai, int solinh = 0, int money = 0, int wave = 0, int dokho = 0, int life = 0)
        {
            this.trangthai = trangthai;
            if (trangthai == 1) name = "THẮNG CUỘC";
            else name = "THUA CUỘC";
            linhdiet = solinh;
            moneyThua = money;
            this.wave = wave;
            this.dokho = dokho;
            isVisible = true;
            this.life = life;
            TongDiem = (linhdiet * 15 + wave * 100 + moneyThua * (trangthai == 1 ? 5 : 2) + dokho * 500 + life * 200);
        }
        public void Load(ContentManager content)
        {
            background = content.Load<Texture2D>("images/menu/infoFrame");
            button = content.Load<Texture2D>("images/playScreen/endGame");
            guidiem = content.Load<Texture2D>("images/playScreen/guiDiem");
        }
        public void Draw(SpriteBatch sprite, SpriteFont font)
        {
            if (trangthai == 0)
            {
                // thong bao thoat
                #region
                sprite.Draw(background, new Vector2(220, 100), new Rectangle(0, 0, 379, 265),
                                                    Color.White, 0, Vector2.Zero, 1.0f, SpriteEffects.None, 0);
                sprite.DrawString(font, "Bạn có muốn tiếp tục chơi không ?", new Vector2(280, 150), Color.White);
                if (isTouchBando)
                {
                    sprite.Draw(button, new Vector2(250, 300), new Rectangle(251, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(button, new Vector2(250, 300), new Rectangle(0, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
                }
                if (isRepeat)
                {
                    sprite.Draw(button, new Vector2(450, 300), new Rectangle(251, 210, 251, 70),
                                                    Color.White, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(button, new Vector2(450, 300), new Rectangle(0, 210, 251, 70),
                                                    Color.White, 0, Vector2.Zero, 0.5f, SpriteEffects.None, 0);
                }
                #endregion
            }
            else
            {
                #region
                sprite.Draw(background, new Vector2(100, 20), new Rectangle(0, 0, 379, 265),
                                                    Color.White, 0, Vector2.Zero, 1.6f, SpriteEffects.None, 0);
                sprite.DrawString(font, name, new Vector2(330, 40), Color.White);
                sprite.DrawString(font, "LOẠI", new Vector2(250, 60), Color.White);
                sprite.DrawString(font, "Lính tiêu diệt", new Vector2(250, 100), Color.White);
                sprite.DrawString(font, "Số đợt", new Vector2(250, 140), Color.White);
                sprite.DrawString(font, "Vàng dư", new Vector2(250, 180), Color.White);
                sprite.DrawString(font, "Số lượng", new Vector2(400, 60), Color.White);
                sprite.DrawString(font, linhdiet.ToString(), new Vector2(400, 100), Color.White);
                sprite.DrawString(font, wave.ToString(), new Vector2(400, 140), Color.White);
                sprite.DrawString(font, moneyThua.ToString(), new Vector2(400, 180), Color.White);
                sprite.DrawString(font, "Điểm", new Vector2(550, 60), Color.White);
                sprite.DrawString(font, (linhdiet * 15).ToString(), new Vector2(550, 100), Color.White);
                sprite.DrawString(font, (wave * 100).ToString(), new Vector2(550, 140), Color.White);
                sprite.DrawString(font, (moneyThua * (trangthai == 1 ? 5 : 2)).ToString(), new Vector2(550, 180), Color.White);
                sprite.DrawString(font, "Thưởng", new Vector2(250, 220), Color.White);
                sprite.DrawString(font, (dokho * 500 + life * 200).ToString(), new Vector2(550, 220), Color.White);
                sprite.DrawString(font, "Tổng điểm", new Vector2(250, 260), Color.White);
                sprite.DrawString(font, TongDiem.ToString(), new Vector2(550, 260), Color.White);
                sprite.DrawString(font, "Điểm cao nhất          " + (MainPage.diemcao.getDiemCao(GamePage.lever) >= TongDiem ? MainPage.diemcao.getDiemCao(GamePage.lever) : TongDiem).ToString(), new Vector2(250, 300), Color.Red);
                if (SelectMapAndStore.capdoselected == 4 && trangthai == 1)
                {
                    sprite.DrawString(font, "Thưởng " + ((GamePage.lever / 2 + 1) * 100).ToString() + " xu", new Vector2(500, 300), Color.Red);
                }
                if (isTouchBando)
                {
                    sprite.Draw(button, new Vector2(150, 350), new Rectangle(251, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(button, new Vector2(150, 350), new Rectangle(0, 70, 251, 70),
                                                     Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                if (isRepeat)
                {
                    sprite.Draw(button, new Vector2(500, 350), new Rectangle(251, 0, 251, 70),
                                                    Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                else
                {
                    sprite.Draw(button, new Vector2(500, 350), new Rectangle(0, 0, 251, 70),
                                                    Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                }
                if (trangthai == 1)
                {
                    if (isGuiDiem)
                    {
                        sprite.Draw(guidiem, new Vector2(325, 350), new Rectangle(251, 0, 251, 71),
                                                        Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                    }
                    else
                    {
                        sprite.Draw(guidiem, new Vector2(325, 350), new Rectangle(0, 0, 251, 71),
                                                        Color.White, 0, Vector2.Zero, 0.6f, SpriteEffects.None, 0);
                    }
                }
                #endregion
            }

        }
        public bool getVisible()
        {
            return isVisible;
        }
        public void setVisible(bool k)
        {
            isVisible = k;
            isTouchBando = false;
            isRepeat = false;
        }
        public int getTongDiem()
        {
            return TongDiem;
        }
        public bool isSelectBando(Vector2 touch)
        {
            if (trangthai == 0) //xử lý bấm ở thoát
            {
                if (touch.X >= 250 && touch.X <= 375 && touch.Y >= 300 && touch.Y <= 335)
                {
                    isTouchBando = true;
                    return true;
                }
                else
                {
                    isTouchBando = false;
                    return false;
                }
            }
            else //xử lý bấm ở thống kê điểm 
            {
                if (touch.X >= 150 && touch.X <= 300 && touch.Y >= 350 && touch.Y <= 392)
                {
                    isTouchBando = true;
                    return true;
                }
                else
                {
                    isTouchBando = false;
                    return false;
                }
            }
        }
        public bool isSelectRepeat(Vector2 touch)
        {
            if (trangthai == 0) //xử lý bấm ở thoát
            {
                if (touch.X >= 450 && touch.X <= 575 && touch.Y >= 300 && touch.Y <= 335)
                {
                    isRepeat = true;
                    return true;
                }
                else
                {
                    isRepeat = false;
                    return false;
                }
            }
            else
            {
                if (touch.X >= 500 && touch.X <= 650 && touch.Y >= 350 && touch.Y <= 392)
                {
                    isRepeat = true;
                    return true;
                }
                else
                {
                    isRepeat = false;
                    return false;
                }
            }

        }
        public bool isSelectGuiDiem(Vector2 touch)
        {
            if (trangthai != 1) //xử lý bấm ở thoát
            {
                isGuiDiem = false;
                return false;
            }
            else
            {
                if (touch.X >= 325 && touch.X <= 475 && touch.Y >= 350 && touch.Y <= 392)
                {
                    isGuiDiem = true;
                    return true;
                }
                else
                {
                    isGuiDiem = false;
                    return false;
                }
            }
        }
        public void setSelectGuiDiem(bool i) { isGuiDiem = i; }
    }

}
